package com.qcxy.gzy.task;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.widget.Toast;

import com.qcxy.gzy.app.MNDFitness;

/**
 * 上传数据
 * 
 * @author scd
 *
 */
public class UploadTrainningDataTask extends BaseAsyncTask<Object, Void, JSONObject> {
    private Activity mActivity = null;

    public UploadTrainningDataTask(Activity a) {
        super(a);
        mActivity = a;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    // 新开启的线程要执行的业务逻辑执行的方法
    @Override
    protected JSONObject doInBackground(Object... params) {
        String openid = (String) params[0];
        String mac = (String) params[1];
        String device_type = (String) params[2];
        JSONArray trainningData = (JSONArray) params[3];
        JSONObject trainingJsonObject = MNDFitness.uploadTrainningData(openid, mac, device_type, trainningData);
        return trainingJsonObject;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        super.onPostExecute(result);
        if (result != null) {
            int resultCode = result.optInt("success");
            if (resultCode == MNDFitness.RESULT_CODE) {// 数据上传成功
//                Toast.makeText(mActivity, "上传成功/Upload success", Toast.LENGTH_SHORT).show();
            } else {// 数据上传失败
                Toast.makeText(mActivity, "上传数据失败001", Toast.LENGTH_SHORT).show();
            }
        } else {
           	Toast.makeText(mActivity, "上传数据失败002", Toast.LENGTH_SHORT).show();
		}
        // 更新UI解析数据
//    	mActivity.onPause();
    }
}
